package com.gzhryc.weixin.xcx.exceptions;

import org.apache.commons.lang3.StringUtils;

public class XcxErrorException extends Exception{

	private static final long serialVersionUID = 1L;
	
	private ErrorResponse errorResponse;
	
	public XcxErrorException(){}

	public XcxErrorException(ErrorResponse errorResponse){
		this.errorResponse = errorResponse;
	}
	
	public static class ErrorResponse{
	
		private String errcode;
		private String errmsg;
		
		public String getErrcode() {
			return errcode;
		}
		public void setErrcode(String errcode) {
			this.errcode = errcode;
		}
		public String getErrmsg() {
			return errmsg;
		}
		public void setErrmsg(String errmsg) {
			this.errmsg = errmsg;
		}
	}

	@Override
	public String getMessage() {
		if(errorResponse != null){
			return "errcode="+errorResponse.getErrcode();
		}
		return super.getMessage();
	}
	
	public static boolean isErrorResponse(String json){
		return StringUtils.contains(json, "errcode");
	}
	
}
